﻿using System;
using System.Windows;
using CustomerList.Model;
using GalaSoft.MvvmLight.Threading;

namespace MyMeetup.Helpers
{
    public class RsvpHelper
    {
        private INavigationService _navigationService;
        private DataService _dataService;

        public RsvpHelper(DataService dataService, INavigationService navigationService)
        {
            _dataService = dataService;
            _navigationService = navigationService;
            DispatcherHelper.Initialize();
        }


        public void SubmitRsvp(string eventId, RSVPType response, Action<RsvpResponse> callback)
        {
            SubmitRsvp(eventId, response, 0, "", callback);
        }


        public void SubmitRsvp(string eventId, RSVPType response, int guestCount, string comments,
                               Action<RsvpResponse> callback)
        {
            if (LicenseHelper.IsTrial())
            {
                _navigationService.NavigateTo(new Uri("/BuyNow.xaml", UriKind.Relative));
                return;
            }

            _dataService.PostEventRsvp(eventId, response, comments, guestCount,
                                       (rsvpResponse) =>
                                           {
                                               string message = "You have successfully RSVP'd to this meetup!";
                                               DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                                                                         {
                                                                                             MessageBox.Show(
                                                                                                 message);
                                                                                             callback(
                                                                                                 rsvpResponse);
                                                                                         });
                                           }, ResponseHelper.ErrorCallback);
        }
    }
}
